package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;


/**
 * test
 *
 * @author normenhansen
 */
public class Main extends SimpleApplication {

    //ArrayList<Geometry> geos = new ArrayList<Geometry>();
    private Geometry player;
    private BulletAppState bulletAppState;

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        
  
        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
//        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
                
        Geometry g = new Geometry("Box", new Box(new Vector3f(0,0,0), 10, 0.1f, 20));        
        g.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));        
        g.getMaterial().setColor("Color", ColorRGBA.Blue); 
        g.addControl(new RigidBodyControl(new MeshCollisionShape(g.getMesh()),0f));
        
        this.bulletAppState.getPhysicsSpace().add(g);
        rootNode.attachChild(g);      
        
        g.getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(-FastMath.QUARTER_PI/7,Vector3f.UNIT_Z));
        g.getControl(RigidBodyControl.class).setFriction(0.0f);

        
        player = new Geometry("Player", new Box(1, 1, 1));
        player.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));        
        player.getMaterial().setColor("Color", ColorRGBA.Red);       
        rootNode.attachChild(player);                
        
        //player.setLocalTranslation(new Vector3f(0,20f,0)); //funktioniert nur wenn es vor dem Physik-Engineteil gemacht wird!
        player.addControl(new RigidBodyControl(10f));
        bulletAppState.getPhysicsSpace().add(player);
        player.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0,30,0)); //anstatt setLocalTranslation benutzen

        
        flyCam.setEnabled(false);
        ModChaseCamera chaseCam = new ModChaseCamera(cam, player, inputManager);
        chaseCam.setDefaultDistance(30f);
        float h_grad = 90f;
        chaseCam.setDefaultHorizontalRotation((float)(h_grad*3.141592/180));
        float v_grad = 30f;
        chaseCam.setDefaultVerticalRotation((float)(v_grad*3.141592/180));
     
        //System.exit(0);
    }

    @Override
    public void simpleUpdate(float tpf) {

    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }

    private void createLevel() {
      
    }
}
